/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package uy.edu.or.uruguayviajes.negocio.mdb;

import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.ActivationConfigProperty;
import javax.ejb.EJB;
import javax.ejb.MessageDriven;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;
import uy.edu.ort.uruguayviajes.negocio.excepciones.ReservaException;
import uy.edu.ort.uruguayviajes.negocio.servicios.impl.ReservaServiceBean;

/**
 *
 * @author magui
 */
@MessageDriven(mappedName = "jms/uruguayViajesQueue", activationConfig = {
    @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
    @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue")
})
public class UruguayViajesMDB implements MessageListener {
    
    @EJB
    ReservaServiceBean fachadaReservas;
    
    public UruguayViajesMDB() {
    }
    
    @Override
    public void onMessage(Message message) {
        TextMessage msg = (TextMessage)message;
        try {
            String texto = msg.getText();
            String[] result = texto.split("\\s");
            fachadaReservas.actualizarReserva(result[0], result[1]);
        } catch (ReservaException ex) {
            Logger.getLogger(UruguayViajesMDB.class.getName()).log(Level.SEVERE, null, ex);
        }
        catch (JMSException e){
            Logger.getLogger(UruguayViajesMDB.class.getName()).log(Level.SEVERE, null, e);
        }
       

    }
}
